package com.firewolf.springcloud.config;

import com.netflix.client.config.IClientConfig;
import com.netflix.loadbalancer.AbstractLoadBalancerRule;
import com.netflix.loadbalancer.ILoadBalancer;
import com.netflix.loadbalancer.Server;

import java.util.List;

/**
 * 作者：刘兴
 * 时间:19/2/13
 **/
public class MyBalanceRule extends AbstractLoadBalancerRule {


    @Override
    public void initWithNiwsConfig(IClientConfig iClientConfig) {

    }

    @Override
    public Server choose(Object key) {

        ILoadBalancer loadBalancer = getLoadBalancer(); //负载均衡的入口
        List<Server> reachableServers = loadBalancer.getReachableServers();  //获取所有可以访问的服务器
        return reachableServers.get(0);
    }
}
